<template>
  <view>
    <view class="searchbox" @click="gotoSearch"><my-search></my-search></view>
    <swiper indicator-dots autoplay :interval="3000" circular>
      <swiper-item v-for="item in swiperList" :key="item.goods_id">
        <navigator class="swiperItem" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`" open-type="navigate"><image :src="item.image_src"></image></navigator>
      </swiper-item>
    </swiper>
    <view class="navlist">
      <view class="navitem" v-for="(item, index) in navList" :key="index" @click="navClickHandler(item)"><image :src="item.image_src"></image></view>
    </view>
    <view class="floorlist">
      <view class="flooritem" v-for="(item, index) in floorList" :key="index">
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <view class="floorbox">
          <navigator :url="'/subpkg/goods_list/goods_list' + item.product_list[0].navigator_url.substr(item.product_list[0].navigator_url.indexOf('?'))" class="floor-left">
            <image :src="item.product_list[0].image_src" :style="{ width: item.product_list[0].image_width + 'rpx' }" mode="widthFix"></image>
          </navigator>
          <view class="floor-right">
            <navigator
              class="floor-right-item"
              v-for="(item2, index2) in item.product_list"
              :key="index2"
              :url="'/subpkg/goods_list/goods_list' + item2.navigator_url.substr(item2.navigator_url.indexOf('?'))"
              open-type="navigate"
            >
              <image :src="item2.image_src" :style="{ width: item2.image_width + 'rpx' }" mode="widthFix" v-if="index2 != 0"></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js';
export default {
  name: 'home',
  mixins: [badgeMix],
  created() {},
  mounted() {},
  onLoad() {
    this.getSwipertList();
    this.getNavList();
    this.getFloorList();
  },
  data() {
    return {
      swiperList: [],
      navList: [],
      floorList: []
    };
  },
  methods: {
    async getSwipertList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata');
      if (res.meta.status !== 200) {
        return uni.$showMsg();
      }
      this.swiperList = res.message;
    },
    async getNavList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/catitems');
      if (res.meta.status !== 200) {
        return uni.$showMsg();
      }
      this.navList = res.message;
    },
    async getFloorList() {
      const { data: res } = await uni.$http.get('/api/public/v1/home/floordata');
      if (res.meta.status !== 200) {
        return uni.$showMsg();
      }
      this.floorList = res.message;
    },
    navClickHandler(item) {
      if (item.name === '分类') {
        uni.switchTab({
          url: '../cate/cate'
        });
      }
    },
    gotoSearch() {
      uni.navigateTo({
        url: '/subpkg/search/search'
      });
    }
  }
};
</script>

<style lang="scss">
swiper {
  height: 330rpx;
}
swiper-item,
swiper-item image,
.swiperItem {
  width: 100%;
  height: 100%;
}
.navlist {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;
  image {
    width: 128rpx;
    height: 140rpx;
  }
}
.floorlist {
  .flooritem {
    .floor-title {
      height: 60rpx;
      width: 100%;
    }
    .floorbox {
      display: flex;
      .floor-left {
        image {
          padding-left: 10px;
        }
      }
      .floor-right {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
      }
    }
  }
}
.searchbox {
  position: sticky;
  top: 0;
  z-index: 999;
}
</style>
